<template>
  <BasicDrawer v-bind="$attrs" @register="registerDrawer" showFooter :title="getTitle" width="100%" @ok="handleSubmit">

    <BasicForm @register="registerForm">

      <template #items="{ model, field }">
      </template>
    </BasicForm>

  </BasicDrawer>
</template>
<script lang="ts" setup>
import {ref, computed, unref, reactive} from 'vue';
import { BasicForm, useForm, ApiSelect } from '@/components/Form';
import { BasicDrawer, useDrawerInner } from '@/components/Drawer';
import {vxeTableColumns, vxeTableFormSchema} from '../dept/role.data';
import { useModal } from "@/components/Modal";
import { useMessage } from "@/hooks/web/useMessage";
import { useUserStore } from "@/store/modules/user";
import {formSchema} from "./role.data";
const userStore = useUserStore();

const [registerModal, { openModal }] = useModal();
const applyViewShow = ref(false);

const emit = defineEmits(['success', 'register']);
const isUpdate = ref(true);
const dataList = ref({});
const { createMessage } = useMessage();

const id = ref("");



const [registerForm, { resetFields, setFieldsValue, validate, clearValidate }] = useForm({
  labelWidth: 160,
  baseColProps: { lg: 8, md: 24 },
  schemas: formSchema,
  showActionButtonGroup: false,
});

const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
  //打开弹层后的回调
  setDrawerProps({ confirmLoading: false });

  isUpdate.value = !!data?.isUpdate;
  id.value = data.id
  dataList.value=data;
  if (unref(isUpdate)) {
  } else {
   

  }
});



const getTitle = computed(() => (!unref(isUpdate) ? '添加车间小组' : '添加车间小组'));

async function handleSubmit() {
  try {
    // let t_list = tableRef.value.getTableData().tableData;
    // values.items = t_list;
    setDrawerProps({ confirmLoading: true });
    // TODO custom api
    let values=await validate();
    createFn(values);

  } finally {
    setDrawerProps({ confirmLoading: false });
  }
}

function createFn(values) {
  emit("success", values);
  closeDrawer();
}





</script>
